#include "MainScreen.h"
#include "Window.h"

using namespace SDL::UTILS;

Window::Window() : AWindow(), m_quit(false), m_currentScreen("editor")
{
}

Window::~Window()
{
}

int Window::Exec()
{
	this->InitAll();

	int tempsPrecedent = 0, tempsActuel = 0, delay = 10;

	while (m_quit == false)
	{
		tempsActuel = SDL_GetTicks();
		if (tempsActuel - tempsPrecedent > delay)
		{
			while (SDL_PollEvent(&m_event))
			{
				switch (m_event.type)
				{
				case SDL_QUIT:
					m_quit = true;
					break ;
				}
				m_screens.Exec();
			}
			m_screens.Manage();
			(this->*m_screenExecutors[m_currentScreen])();
			m_screens.Draw();
			SDL_Flip(m_screen);
			tempsPrecedent = tempsActuel;
		}
		else
			SDL_Delay(delay - (tempsActuel - tempsPrecedent));
	}

	return (EXIT_SUCCESS);
}

void Window::LoadScreen(std::string const& _name, ScreenManager::MngrFunc,
						IArgs* _datas, bool _delete)
{
}

void Window::EditorScreenExec()
{
}

void Window::SimulatorScreenExec()
{
}

void Window::ManageEvents()
{
}

void Window::InitAll()
{
	m_screenExecutors["editor"] = &Window::EditorScreenExec;
	m_screenExecutors["simulator"] = &Window::SimulatorScreenExec;

	m_screens.Add("main", new MainScreen(m_screen, &m_event), MainScreen::Manage,
				  new MainArgs(m_screen, &m_event));
}
